package com.lsa.edmonds.chap10;

import java.util.Comparator;
import java.util.List;

import com.lsa.helpers.heap.ArrayHeap;
import com.lsa.shenn.common.Sorter;

/**
 * We test pop method by using the fact the largest element always returned
 */
public class TestArrayHeapPop implements Sorter{

	@Override
	public int[] sort(int[] array) {
		if (array.length == 0) return array;
		ArrayHeap<Integer> arrayHeap = new ArrayHeap<Integer>(new Comparator<Integer>(){
			@Override
			public int compare(Integer o1, Integer o2) {
				return o2 - o1;
			}
		});
		
		for (int i : array) {
			arrayHeap.insert(i);
		}
		
		int[] result = new int[array.length];
		int i = 0;
		while(arrayHeap.getSize() > 0){
			result[i++] = arrayHeap.pop();
		}
		return result;
	}

	@Override
	public List<Integer> sort(List<Integer> array) {
		throw new IllegalArgumentException();
	}
}
